package eu.pago.chat.gui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class ConversationFrame extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JTextArea areaSend;
	private JTextArea areaView;

	public ConversationFrame(String partnerName) {
		this.setSize(500, 500);
		this.setTitle(partnerName);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLayout(new BorderLayout());
		this.add(createViewPanel(), BorderLayout.CENTER);
		this.add(createWritePanel(), BorderLayout.SOUTH);
	}

	private Component createWritePanel() {
		JPanel writePanel = new JPanel();
		areaSend = new JTextArea("", 6, 36);
		areaSend.setBackground(UtilColors.FADE_VIOLET);
		areaSend.setLineWrap(true);
		JScrollPane spane = new JScrollPane(areaSend, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

		JButton sendButton = new JButton("Send");
		sendButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent evt) {
				// ... called when button clicked
				areaView.append(areaSend.getText());

			}
		});
		writePanel.add(spane);
		writePanel.add(sendButton);
		writePanel.setBackground(UtilColors.BLUE_NUANCE);
		return writePanel;
	}

	private Component createViewPanel() {
		JPanel viewPanel = new JPanel();
		areaView = new JTextArea("", 24, 43);
		areaView.setBackground(UtilColors.FADE_VIOLET);
		JScrollPane spane = new JScrollPane(areaView, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		areaView.setLineWrap(true);
		areaView.setEditable(false);
		viewPanel.add(spane);

		viewPanel.setBackground(UtilColors.BLUE_NUANCE);
		return viewPanel;
	}
}
